{ L PRINTER:}
{$R-}
(* BYTE Benchmark - see issue Sept '81 for data on other machines/languages*)

(* Eratosthenes Sieve Prime Number Program in (UCSD) PASCAL *)

(*     With obvious UCSD optimisations, 
       eg make the main computation a procedure to get SSTLs,
          turn range checking off  *)

(*     Making such changes to a benchmark is clearly not in the spirit of
       comparative testing.  However, the changes shown do serve to show
       how you might speed up your own programs - or teach you to beware
       of benchmarks!!
       
       USUS(UK) Library Reviewer   *)

PROGRAM benchbyte;

CONST
  size = 8190;
  
VAR
  flags : ARRAY [0..size] OF BOOLEAN;
  
PROCEDURE do_it;

  VAR
    i,prime,k,count,iter : INTEGER;
  
  BEGIN
    WRITELN('10 iterations');
    FOR iter := 1 TO 10 DO BEGIN
      count := 0;
      FILLCHAR(flags,SIZEOF(flags),CHR(ORD(TRUE)));
      FOR i := 0 TO size DO
        IF flags[i] THEN BEGIN
          prime := i+i+3;
          k := i + prime;
          WHILE k <= size DO BEGIN
            flags[k] := FALSE;
            k := k + prime;
          END;
          count := count + 1;
        WRITELN(prime);
        END;
      END;
    WRITELN(count,' primes');
  END;

BEGIN
  do_it;
END.

